{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already up-to-date: plotly in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (3.10.0)\n",
      "Requirement already satisfied, skipping upgrade: decorator>=4.0.6 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from plotly) (4.3.0)\n",
      "Requirement already satisfied, skipping upgrade: pytz in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from plotly) (2018.7)\n",
      "Requirement already satisfied, skipping upgrade: six in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from plotly) (1.12.0)\n",
      "Requirement already satisfied, skipping upgrade: nbformat>=4.2 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from plotly) (4.4.0)\n",
      "Requirement already satisfied, skipping upgrade: requests in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from plotly) (2.21.0)\n",
      "Requirement already satisfied, skipping upgrade: retrying>=1.3.3 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from plotly) (1.3.3)\n",
      "Requirement already satisfied, skipping upgrade: ipython-genutils in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (0.2.0)\n",
      "Requirement already satisfied, skipping upgrade: jupyter-core in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (4.4.0)\n",
      "Requirement already satisfied, skipping upgrade: jsonschema!=2.5.0,>=2.4 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (2.6.0)\n",
      "Requirement already satisfied, skipping upgrade: traitlets>=4.1 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly) (4.3.2)\n",
      "Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from requests->plotly) (2019.3.9)\n",
      "Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from requests->plotly) (2.8)\n",
      "Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from requests->plotly) (1.24.1)\n",
      "Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /Users/wangzheng/anaconda3/lib/python3.7/site-packages (from requests->plotly) (3.0.4)\n",
      "\u001b[33mYou are using pip version 19.0.3, however version 19.1.1 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install --upgrade plotly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "        <script type=\"text/javascript\">\n",
       "        window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
       "        if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
       "        if (typeof require !== 'undefined') {\n",
       "        require.undef(\"plotly\");\n",
       "        requirejs.config({\n",
       "            paths: {\n",
       "                'plotly': ['https://cdn.plot.ly/plotly-latest.min']\n",
       "            }\n",
       "        });\n",
       "        require(['plotly'], function(Plotly) {\n",
       "            window._Plotly = Plotly;\n",
       "        });\n",
       "        }\n",
       "        </script>\n",
       "        "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import plotly\n",
    "import plotly.graph_objs as go\n",
    "import numpy as np\n",
    "plotly.offline.init_notebook_mode(connected=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic Box Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "linkText": "Export to plot.ly",
        "plotlyServerURL": "https://plot.ly",
        "showLink": false
       },
       "data": [
        {
         "type": "box",
         "uid": "aad030f0-079a-47b8-a9ec-85eb39c052a8",
         "y": [
          -1.2206307208004736,
          -0.8037728421543281,
          -0.6452428898466511,
          -1.0144078916201247,
          -0.5461667086567175,
          -0.5564926350117336,
          -2.238626232968876,
          -1.1494184405217174,
          -2.4945865116091728,
          0.9511980343021014,
          -2.8375138881082167,
          -0.6712799937564566,
          -1.8476770409737975,
          1.6570421375812865,
          -1.4841465513381829,
          0.24685882649889823,
          -0.931152312725226,
          0.45744983349400115,
          -2.342864367971336,
          -1.8495022103118872,
          -1.1684181549678352,
          -0.0571835055573392,
          -1.0772750770181705,
          -0.0061886133067838855,
          -2.265488178870801,
          0.6927066882496995,
          -0.9215795627993754,
          0.6143932438978059,
          -3.091268207988221,
          -1.6737387168250342,
          0.7812229785351203,
          -1.219432826184356,
          -2.065695400659717,
          -1.7693298177012056,
          -1.2899667528424246,
          0.9497039649429269,
          -0.14906566277382727,
          -0.6378359390962075,
          -1.6057969117687638,
          -1.53465661342543,
          0.06718962438156817,
          -2.212354361641073,
          -0.08941184597386787,
          -0.4980838641043466,
          0.3227760108524129,
          0.7814987775015307,
          -0.6939712810597867,
          -1.6738377151728088,
          -1.340113493804099,
          0.3285674671280401
         ]
        },
        {
         "type": "box",
         "uid": "66a9f9b0-3c03-4ef6-89be-f8a798d792ac",
         "y": [
          0.3031667713140367,
          1.9971188419146386,
          -0.3533970087036471,
          0.5335324616768278,
          0.9842183401206707,
          0.1562815114121795,
          1.2376709222392508,
          0.6624610527622505,
          1.2208885442672803,
          0.9841662186690517,
          1.6224688947213242,
          1.410193343973502,
          0.7457707207474106,
          2.5797198202557015,
          1.8346109367907775,
          0.4808267312373252,
          0.7888673477287413,
          3.4933842329827236,
          0.9659316884391046,
          2.9059482186343066,
          0.4035498696674076,
          -0.27590586885761104,
          1.8399392768531886,
          -0.030423388296658693,
          2.0811025673717722,
          0.6087443663432706,
          1.3461595477720534,
          -0.6439537989113189,
          1.2725362694924878,
          0.017753833464116964,
          0.2988706930799424,
          0.8064451613916558,
          0.360742465847099,
          1.975225484106805,
          2.7668060922020077,
          1.2634312874781484,
          0.7450846269067679,
          0.5813834053945701,
          1.137282745074066,
          1.5289198270897666,
          -0.21725471900862803,
          1.5096145229858164,
          0.7633520613747699,
          0.8664204974783513,
          0.5309868297655922,
          -1.0231887704595395,
          2.0236215320485362,
          0.8181768459688595,
          0.873310612375575,
          0.46327836475633377
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div>\n",
       "        \n",
       "        \n",
       "            <div id=\"21c5d129-4a84-4657-a088-e17a342694c4\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                require([\"plotly\"], function(Plotly) {\n",
       "                    window.PLOTLYENV=window.PLOTLYENV || {};\n",
       "                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n",
       "                    \n",
       "                if (document.getElementById(\"21c5d129-4a84-4657-a088-e17a342694c4\")) {\n",
       "                    Plotly.newPlot(\n",
       "                        '21c5d129-4a84-4657-a088-e17a342694c4',\n",
       "                        [{\"type\": \"box\", \"uid\": \"aad030f0-079a-47b8-a9ec-85eb39c052a8\", \"y\": [-1.2206307208004736, -0.8037728421543281, -0.6452428898466511, -1.0144078916201247, -0.5461667086567175, -0.5564926350117336, -2.238626232968876, -1.1494184405217174, -2.4945865116091728, 0.9511980343021014, -2.8375138881082167, -0.6712799937564566, -1.8476770409737975, 1.6570421375812865, -1.4841465513381829, 0.24685882649889823, -0.931152312725226, 0.45744983349400115, -2.342864367971336, -1.8495022103118872, -1.1684181549678352, -0.0571835055573392, -1.0772750770181705, -0.0061886133067838855, -2.265488178870801, 0.6927066882496995, -0.9215795627993754, 0.6143932438978059, -3.091268207988221, -1.6737387168250342, 0.7812229785351203, -1.219432826184356, -2.065695400659717, -1.7693298177012056, -1.2899667528424246, 0.9497039649429269, -0.14906566277382727, -0.6378359390962075, -1.6057969117687638, -1.53465661342543, 0.06718962438156817, -2.212354361641073, -0.08941184597386787, -0.4980838641043466, 0.3227760108524129, 0.7814987775015307, -0.6939712810597867, -1.6738377151728088, -1.340113493804099, 0.3285674671280401]}, {\"type\": \"box\", \"uid\": \"66a9f9b0-3c03-4ef6-89be-f8a798d792ac\", \"y\": [0.3031667713140367, 1.9971188419146386, -0.3533970087036471, 0.5335324616768278, 0.9842183401206707, 0.1562815114121795, 1.2376709222392508, 0.6624610527622505, 1.2208885442672803, 0.9841662186690517, 1.6224688947213242, 1.410193343973502, 0.7457707207474106, 2.5797198202557015, 1.8346109367907775, 0.4808267312373252, 0.7888673477287413, 3.4933842329827236, 0.9659316884391046, 2.9059482186343066, 0.4035498696674076, -0.27590586885761104, 1.8399392768531886, -0.030423388296658693, 2.0811025673717722, 0.6087443663432706, 1.3461595477720534, -0.6439537989113189, 1.2725362694924878, 0.017753833464116964, 0.2988706930799424, 0.8064451613916558, 0.360742465847099, 1.975225484106805, 2.7668060922020077, 1.2634312874781484, 0.7450846269067679, 0.5813834053945701, 1.137282745074066, 1.5289198270897666, -0.21725471900862803, 1.5096145229858164, 0.7633520613747699, 0.8664204974783513, 0.5309868297655922, -1.0231887704595395, 2.0236215320485362, 0.8181768459688595, 0.873310612375575, 0.46327836475633377]}],\n",
       "                        {},\n",
       "                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n",
       "                    ).then(function(){\n",
       "                            \n",
       "var gd = document.getElementById('21c5d129-4a84-4657-a088-e17a342694c4');\n",
       "var x = new MutationObserver(function (mutations, observer) {{\n",
       "        var display = window.getComputedStyle(gd).display;\n",
       "        if (!display || display === 'none') {{\n",
       "            console.log([gd, 'removed!']);\n",
       "            Plotly.purge(gd);\n",
       "            observer.disconnect();\n",
       "        }}\n",
       "}});\n",
       "\n",
       "// Listen for the removal of the full notebook cells\n",
       "var notebookContainer = gd.closest('#notebook-container');\n",
       "if (notebookContainer) {{\n",
       "    x.observe(notebookContainer, {childList: true});\n",
       "}}\n",
       "\n",
       "// Listen for the clearing of the current output cell\n",
       "var outputEl = gd.closest('.output');\n",
       "if (outputEl) {{\n",
       "    x.observe(outputEl, {childList: true});\n",
       "}}\n",
       "\n",
       "                        })\n",
       "                };\n",
       "                });\n",
       "            </script>\n",
       "        </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_0 = np.random.randn(50)-1\n",
    "_1 = np.random.randn(50)+1\n",
    "\n",
    "# X轴\n",
    "# trace0 = go.Box(x=_0)\n",
    "# trace1 = go.Box(x=_1)\n",
    "\n",
    "# Y轴\n",
    "trace0 = go.Box(y=_0)\n",
    "trace1 = go.Box(y=_1)\n",
    "\n",
    "data = [trace0, trace1]\n",
    "plotly.offline.iplot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Grouped Box Plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "linkText": "Export to plot.ly",
        "plotlyServerURL": "https://plot.ly",
        "showLink": false
       },
       "data": [
        {
         "marker": {
          "color": "#3D9970"
         },
         "name": "kale",
         "type": "box",
         "uid": "3bfdda12-f407-4b88-94a6-b261961e6e20",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.2,
          0.2,
          0.6,
          1,
          0.5,
          0.4,
          0.2,
          0.7,
          0.9,
          0.1,
          0.5,
          0.3
         ]
        },
        {
         "marker": {
          "color": "#FF4136"
         },
         "name": "radishes",
         "type": "box",
         "uid": "e105df37-8c8c-4c54-ba84-fdeda4c3ef82",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.6,
          0.7,
          0.3,
          0.6,
          0,
          0.5,
          0.7,
          0.9,
          0.5,
          0.8,
          0.7,
          0.2
         ]
        },
        {
         "marker": {
          "color": "#FF851B"
         },
         "name": "carrots",
         "type": "box",
         "uid": "75c2d41c-3a26-4057-b74f-3290b3e0ea0c",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.1,
          0.3,
          0.1,
          0.9,
          0.6,
          0.6,
          0.9,
          1,
          0.3,
          0.6,
          0.8,
          0.5
         ]
        }
       ],
       "layout": {
        "boxmode": "group",
        "yaxis": {
         "title": {
          "text": "normalized moisture"
         },
         "zeroline": false
        }
       }
      },
      "text/html": [
       "<div>\n",
       "        \n",
       "        \n",
       "            <div id=\"1c2ba74e-093f-4f96-9516-c571a3feb74f\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                require([\"plotly\"], function(Plotly) {\n",
       "                    window.PLOTLYENV=window.PLOTLYENV || {};\n",
       "                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n",
       "                    \n",
       "                if (document.getElementById(\"1c2ba74e-093f-4f96-9516-c571a3feb74f\")) {\n",
       "                    Plotly.newPlot(\n",
       "                        '1c2ba74e-093f-4f96-9516-c571a3feb74f',\n",
       "                        [{\"marker\": {\"color\": \"#3D9970\"}, \"name\": \"kale\", \"type\": \"box\", \"uid\": \"3bfdda12-f407-4b88-94a6-b261961e6e20\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3]}, {\"marker\": {\"color\": \"#FF4136\"}, \"name\": \"radishes\", \"type\": \"box\", \"uid\": \"e105df37-8c8c-4c54-ba84-fdeda4c3ef82\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2]}, {\"marker\": {\"color\": \"#FF851B\"}, \"name\": \"carrots\", \"type\": \"box\", \"uid\": \"75c2d41c-3a26-4057-b74f-3290b3e0ea0c\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5]}],\n",
       "                        {\"boxmode\": \"group\", \"yaxis\": {\"title\": {\"text\": \"normalized moisture\"}, \"zeroline\": false}},\n",
       "                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n",
       "                    ).then(function(){\n",
       "                            \n",
       "var gd = document.getElementById('1c2ba74e-093f-4f96-9516-c571a3feb74f');\n",
       "var x = new MutationObserver(function (mutations, observer) {{\n",
       "        var display = window.getComputedStyle(gd).display;\n",
       "        if (!display || display === 'none') {{\n",
       "            console.log([gd, 'removed!']);\n",
       "            Plotly.purge(gd);\n",
       "            observer.disconnect();\n",
       "        }}\n",
       "}});\n",
       "\n",
       "// Listen for the removal of the full notebook cells\n",
       "var notebookContainer = gd.closest('#notebook-container');\n",
       "if (notebookContainer) {{\n",
       "    x.observe(notebookContainer, {childList: true});\n",
       "}}\n",
       "\n",
       "// Listen for the clearing of the current output cell\n",
       "var outputEl = gd.closest('.output');\n",
       "if (outputEl) {{\n",
       "    x.observe(outputEl, {childList: true});\n",
       "}}\n",
       "\n",
       "                        })\n",
       "                };\n",
       "                });\n",
       "            </script>\n",
       "        </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']\n",
    "\n",
    "trace0 = go.Box(\n",
    "    y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],\n",
    "    x=x,\n",
    "    name='kale',\n",
    "    marker=dict(color='#3D9970')\n",
    ")\n",
    "trace1 = go.Box(\n",
    "    y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],\n",
    "    x=x,\n",
    "    name='radishes',\n",
    "    marker=dict(color='#FF4136')\n",
    ")\n",
    "trace2 = go.Box(\n",
    "    y=[0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],\n",
    "    x=x,\n",
    "    name='carrots',\n",
    "    marker=dict(color='#FF851B')\n",
    ")\n",
    "\n",
    "data = [trace0, trace1, trace2]\n",
    "layout = go.Layout(\n",
    "    yaxis=dict(\n",
    "        title='normalized moisture',\n",
    "        zeroline=False\n",
    "    ),\n",
    "    boxmode='group'\n",
    ")\n",
    "fig = go.Figure(data=data, layout=layout)\n",
    "plotly.offline.iplot(fig)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
